#include<iostream>
#include<cstdlib>
#include<string>
#include<cstdio>
#include <WinSock2.h>
#include <WS2tcpip.h> 
#include <Windows.h>

using namespace std;
#pragma warning(disable:4996)

#pragma comment(lib,"ws2_32.lib")

uint16_t serverport = 8888;
string serverip = "192.168.52.128";

int main()
{
	WSADATA wsd;
	WSAStartup(MAKEWORD(2, 2), &wsd);

	struct sockaddr_in server;
	memset(&server, 0, sizeof(server));
	server.sin_family = AF_INET;
	server.sin_port = htons(serverport);
	server.sin_addr.s_addr = inet_addr(serverip.c_str());

	SOCKET sockfd = socket(AF_INET, SOCK_DGRAM, 0);
	if (sockfd ==SOCKET_ERROR)
	{
		cout << "socker error" << endl;
		return 1;
	}
	string msg;
	char buffer[1024];
	while (1)
	{
		cout << "Please Enter: ";
		getline(cin, msg);

		sendto(sockfd, msg.c_str(), (int)msg.size(), 0, (struct sockaddr*)&server,sizeof(server));
		
		struct sockaddr_in tmp;
		int len = sizeof(tmp);

		int s = recvfrom(sockfd, buffer, 1023, 0, (struct sockaddr*)&tmp, &len);
		if (s > 0)
		{
			buffer[s] = 0;
			cout << buffer << endl;
		}
	}
	closesocket(sockfd);

	WSACleanup();

	return 0;
}